//app.js
const key = require("./utils/config")
App({
  globalData: {
    currentCity: "南昌"
  },


  onLaunch: function () {
    // 设置缓存
    let nowCity = wx.getStorageSync('nowCity')
    if(nowCity){
    }else{
      wx.setStorageSync('nowCity', [])
    }
    // 请求经纬度
    wx.getLocation({
      type: 'wgs84',
      success: (res)=>{
        var url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=${key}`
        // 根据百度地图api获取城市
        wx.request({
          url,
          data: {},
          method: 'GET',
          success: (res)=>{
            console.log(res.data.result.address_component.city);
            // 用回调来处理异步加载问题
            if(this.callback){
              this.globalData.currentCity = res.data.result.address_component.city
              wx.setStorageSync('nowCity', res.data.result.address_component.city)
              this.callback()
            }
          }
        })
      }
    })
  },

})